package controller;

import Model.Calculator;
import services.BasicOperation;
import services.PowerFuntion;
import services.TrigonometricFunction;

/**
*
* @author Natalia
*/

public class CalculatorController {

    private String operation;

    private Calculator calculator = new Calculator();

    private BasicOperation basicOperation = new BasicOperation();
    private TrigonometricFunction trigonometricFunction = new TrigonometricFunction();
    private PowerFuntion powerFuntion = new PowerFuntion();

    public void add(Float a) {
        calculator.setA(a);
        operation = "add" ;
    }

    public void sustract(Float a) {
        calculator.setA(a);
        operation = "sus" ;
    }

    public void multiply(Float a) {
        calculator.setA(a);
        operation = "mul" ;
    }

    public void divide(Float a) {
        calculator.setA(a);
        operation = "div" ;
    }

    public float exp(Float a) {
         calculator.setA(a);
        return (powerFuntion.exp( calculator ));
    }

    public float log(Float a) {
        calculator.setA(a);
        return (powerFuntion.log( calculator ));
    }

    public float sin(Float a) {
        calculator.setA(a);
        return (trigonometricFunction.sin( calculator ));
    }

    public float cos(Float a) {
        calculator.setA(a);
        return (trigonometricFunction.cos( calculator ));
    }

    public float result(Float b) throws NumberFormatException {
       /* if(operation.compareTo("sin")==0){
            return trigonometricFunction.sin( calculator );
        }else if(operation.compareTo("cos")==0){
            return trigonometricFunct/ion.cos( calculator );
        }else if(operation.compareTo("exp")==0){
            return trigonometricFunction.cos( calculator );
        }else if(operation.compareTo("log")==0){
            return trigonometricFunction.cos( calculator );
        }*/
        calculator.setB(b);
        if( operation.compareTo("add") == 0 ){
            return basicOperation.add( calculator );
        } else if( operation.compareTo("sus") == 0 ){
            return basicOperation.sustract( calculator );
        } else if( operation.compareTo("mul") == 0 ){
            return basicOperation.multiply( calculator );
        } else if( operation.compareTo("div") == 0 ){
            return basicOperation.divide( calculator );
        } else {
            throw new NumberFormatException("No operation definida");
        }
    }

}
